<template>
	<view class="content">
		<view class="head">
			<image src="../../static/headBack.png" mode="aspectFit"></image>
		</view>
		<view class="detail">
			<view class="list bottom">
				<view class="title">
					收费单位
				</view>
				<view class="label">
					临颍县盛宏热力有限公司
				</view>
			</view>
			<view class="list bottom">
				<view class="title">
					缴费户号
				</view>
				<view class="label">
					{{detail.number}}
				</view>
			</view>
			<view class="list bottom">
				<view class="title">
					户名
				</view>
				<view class="label">
					{{detail.user_name}}
				</view>
			</view>
			<view class="list bottom">
				<view class="title">
					详细住址
				</view>
				<view class="label">
					{{detail.address}}
				</view>
			</view>
			<view class="list">
				<view class="title">
					缴费项目
				</view>
				<view class="label">
					{{detail.project_name}}
				</view>
			</view>
		</view>
		<view class="price">
			<view class="title">
				缴费金额
			</view>
			<view class="label">
				{{detail.money}}
			</view>
		</view>
		<button type="primary" v-if="type == 1" @click="submit()">下一步</button>
	</view>
</template>

<script>
	import jWeixin from 'jweixin-module'
	export default {
		data(){
			return {
				detail:{
					address: "",
					money: "",
					number: "",
					project_name: "",
					user_name: ""
				},
				type: 1,
				com_id: 2
			}
		},
		onLoad(option) {
			this.com_id = option.com_id;
			this.type = option.type;
			if(option.type == 2){
				this.load(option.id)
			}else{
				this.detail = JSON.parse(option.detail);
			}
		},
		onShow() {
			uni.removeStorageSync('href')
		},
		methods:{
			async load(id){
				let res = await this.api.uniRequ(this.api.public.order_info,{id: id});
				if(res.code == 1){
					this.detail = res.data;
					// this.$framDate.showToast(JSON.stringify(res.data));
				}
			},
			async submit(){
				let that = this;
				let params = {
					number: this.detail.number,
					pay_type: 1,
					community_id: this.com_id
				}
				// #ifdef MP-WEIXIN
				// params.pay_type = 1;
				// #endif
				// #ifdef MP-ALIPAY
				// params.pay_type = 2;
				// #endif
				let res = await this.api.uniRequ(this.api.public.order_add,params);
				if(res.code == 1){
					// #ifdef 
					// this.order_pay(JSON.parse(res.data.data))
					this.order_pay(res.data.data)
					// #endif
					// #ifdef MP-ALIPAY
					// uni.requestPayment({
					// 	provider:"alipay",
					// 	orderInfo: res.data.data,
					// 	complete(e) {
					// 		console.log(e)
					// 		that.$framDate.showToast(JSON.stringify(e))
					// 		if(e.resultCode == 9000){
					// 			that.$framDate.redTo('index/status?status=0')
					// 		}
					// 		if(e.resultCode != 9000){
					// 			that.$framDate.navTo('index/status?status=1')
					// 		}
					// 	}
					// })
					// #endif
					// #ifdef MP-WEIXIN
					// let obj = JSON.parse(res.data.data)
					// let obj = res.data.data
					// wx.requestPayment({
					// 	timeStamp: obj.TimeStamp,
					// 	nonceStr: obj.Charset,
					// 	package:obj.InnerFundTransNbr,
					// 	signType:obj.SignType,
					// 	paySign: obj.Sign,
					// 	complete(e) {
					// 		console.log(e)
					// 	}
					// })
					// #endif
				}
			},
			order_pay(detail) {
				let that = this;
				jWeixin.config({
					// appId: detail.appId,
					// timestamp: detail.timeStamp,
					// nonceStr: detail.nonceStr,
					// signature: detail.paySign,
					appId: detail.AppId,
					timestamp: detail.TimeStamp,
					nonceStr: detail.Charset,
					signature: detail.Sign,
					debug: false,
					jsApiList: ['chooseWXPay']
				});
			
				jWeixin.ready(function() {
					uni.hideLoading();
					jWeixin.chooseWXPay({
						// appId: detail.appId,
						// timestamp: detail.timeStamp,
						// nonceStr: detail.nonceStr,
						// package: detail.package,
						// signType: detail.signType,
						// paySign: detail.paySign,
						appId: detail.AppId,
						timestamp: detail.TimeStamp,
						nonceStr: detail.Charset,
						package: detail.Subject,
						signType: detail.SignType,
						paySign: detail.Sign,
						success: function(res) {
							that.$framDate.navBack();
						},
						cancel: function(res) {
							that.$framDate.showToast('用户取消支付')
							if(that.type == 1){
								that.submit_update();
							}else if(that.type == 3){
								that.refresh();
							}
						},
						fail: function(res) {
							that.$framDate.navBack();
						}
					});
				})
			
			}
		}
	}
</script>

<style lang="scss">
	.detail{
		width: 88%;
		padding: 40rpx 3%;
		background-color: #FFFFFF;
		position: relative;
		z-index: 1;
		left: 3%;
		top: -150rpx;
		box-shadow: 0px -5rpx 20rpx rgba(0, 0, 0, 0.1);
		.list{
			width: 100%;
			// height: 37rpx;
			line-height: 37rpx;
			padding: 30rpx 0;
			font-size: 26rpx;
			display: flex;
			.title{
				width: 20%;
				color: #262628;
			}
			.label{
				width: 80%;
				text-align: right;
				color: #707080;
				font-weight: bold;
			}
		}
		.bottom{
			border-bottom: 1px solid #EFEFF4;
		}
	}
	.price{
		width: 88%;
		padding: 0rpx 3%;
		background-color: #FFFFFF;
		z-index: 1;
		position: relative;
		left: 3%;
		top: -106rpx;
		box-shadow: 0px -5rpx 20rpx rgba(0, 0, 0, 0.1);
		height: 132rpx;
		line-height: 132rpx;
		font-size: 40rpx;
		color: #262628;
		font-weight: bold;
		display: flex;
		view{
			width: 50%;
		}
		.label{
			text-align: right;
		}
	}
	button[type="primary"]{
		background-color: #F65534;
		height: 93rpx;
		line-height: 93rpx;
		font-size: 33rpx;
		width: 80%;
		top: -56rpx;
		position: relative;
		z-index: 1;
	}
</style>
